﻿Imports Microsoft.Win32
Imports System.Net
Imports System.Xml

Public Class Data
    Public Structure VersionInfo
        Dim db_version As String
        Dim user_version As String
        Dim size As String
        Dim launch As String
        Dim notes As String
    End Structure

    Shared osInfo As OperatingSystem = System.Environment.OSVersion

    Shared Function getWindowsRunningMode() As Integer
        If IntPtr.Size = 8 Then
            Return 64
        Else
            Return 32
        End If
    End Function

    Shared Function IsConnectionAvailable()
        Dim objUrl As New System.Uri("http://www.serysoft.com/")
        Dim objWebReq As WebRequest
        objWebReq = WebRequest.Create(objUrl)
        Dim objResp As WebResponse
        Try
            objResp = objWebReq.GetResponse
            Return True
        Catch ex As Exception
            Return False
        End Try
        objWebReq = Nothing
        objResp.Close()
    End Function

    Shared Function GetVersionInformation() As VersionInfo
        Dim regshell As RegistryKey

        If getWindowsRunningMode() = 64 Then
            regshell = Registry.LocalMachine.OpenSubKey("Software\Wow6432Node\SysPad", False)
        Else
            regshell = Registry.LocalMachine.OpenSubKey("Software\SysPad", False)
        End If

        Dim vi As New VersionInfo
        Dim doc As New XmlDocument

        If regshell IsNot Nothing Then
            Dim currentVersion As String = regshell.GetValue("Version")
            Try
                doc.Load("http://www.serysoft.com/webservice/sp_version.php")
                vi.user_version = currentVersion
                vi.db_version = doc.SelectSingleNode("/version_info/version").InnerXml
                vi.size = doc.SelectSingleNode("/version_info/size").InnerXml
                vi.launch = doc.SelectSingleNode("/version_info/launch").InnerXml
                vi.notes = doc.SelectSingleNode("/version_info/notes").InnerXml
            Catch ex As Exception
                Console.Write(ex.ToString)
            Finally
                regshell.Close()
            End Try
        End If

        Return vi
    End Function
End Class
